/**
 * @Copyright (C) 2019 广州金鹏集团有限公司.
 * 本系统是商用软件,未经授权擅自复制或传播本程序的部分或全部将是非法的.
 * @创建人: 赵力
 * @创建时间: 2019-01-23 09:39
 * @版本: V1.0
 */
package com.ikcai.enginegraph.service.impl;

import com.ikcai.enginegraph.domain.base.BaseNode;
import com.ikcai.enginegraph.domain.base.BaseRelationship;
import com.ikcai.enginegraph.respository.BaseRelationshipRepository;
import com.ikcai.enginegraph.service.IBaseRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @类功能说明:
 * @创建人: 赵力
 * @创建时间: 2019-01-23 09:39
 */
@Service
public class BaseRelationshipServiceImpl implements IBaseRelationshipService {

    @Autowired
    BaseRelationshipRepository refRepository;

    @Override
    public BaseRelationship addRelationship(BaseRelationship relationship) {
        return refRepository.save(relationship);
    }

    @Override
    public BaseRelationship addRelationship(String name, BaseNode startNode, BaseNode endNode) {
        BaseRelationship relationship = new BaseRelationship(name,startNode,endNode);
        return refRepository.save(relationship);
    }

    @Override
    public boolean deleteRelationshipById(Long id) {
         refRepository.deleteById(id);
         return true;
    }

    @Override
    public BaseRelationship findPersonRelationshipByName(String name, String startName, String endName) {
        List<BaseRelationship> ships = refRepository.findPersonRelationshipByName(name,startName,endName);
        if(ships != null && ships.size()>0) {
            return ships.get(0);
        }
        return null;
    }

}
